// JavaScript Document
window.onload = function(){  
    console.log(document.getElementsByTagName('main'))
  for(var j=0; j<document.getElementsByTagName('main').length; j++){
      console.log(j)
    strYYYY = document.getElementsByTagName('main')[j].children.YYYY.outerHTML; 
    strMM = document.getElementsByTagName('main')[j].children.MM.outerHTML;  
    strDD = document.getElementsByTagName('main')[j].children.DD.outerHTML;  
    MonHead = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];  
    //先给年下拉框赋内容  
    var y = new Date().getFullYear();  
    var str = strYYYY.substring(0, strYYYY.length - 9);  
    for (var i = (y-22); i < (y-12); i++) //以今年为准，前30年，后1年  
    {  
    str += "<option value='" + i + "'> " + i + "</option>\r\n";  
    }  
    document.getElementsByTagName('main')[j].children.YYYY.outerHTML = str +"</select>";  
    // document.getElementsByTagName('main')[j].children.YYYY.value = y;  
    //赋月份的下拉框  
    var str = strMM.substring(0, strMM.length - 9);  
    for (var i = 1; i < 13; i++)  
    {  
    str += "<option value='" + i + "'> " + i + "</option>\r\n";  
    }  
    document.getElementsByTagName('main')[j].children.MM.outerHTML = str +"</select>";  
  
    //document.getElementsByTagName('main')[j].children.MM.value = new Date().getMonth() + 1; 
      //赋日期下拉框 
    //
    //     
    var n = MonHead[new Date().getMonth()];  
    if (new Date().getMonth() ==1 && IsPinYear(YYYYvalue)) n++;  
    writeDay(n,j); //赋日期下拉框  
    // document.getElementsByTagName('main')[j].children.DD.value = new Date().getDate();  
    } 
  } 
  function YYYYMM(str,e) //年发生变化时日期发生变化(主要是判断闰平年)  
  {  
   // e 是第几个main表单 如果没有传参默认第一个
  if(e == undefined){
    e = 0
  }
  var MMvalue = document.getElementsByTagName('main')[e].children.MM.options[document.getElementsByTagName('main')[e].children.MM.selectedIndex].value;  
  if (MMvalue == ""){DD.outerHTML = strDD; return;}  
  var n = MonHead[MMvalue - 1];  
  if (MMvalue ==2 && IsPinYear(str)) n++;  
  writeDay(n,e)  
  }  
  function MMDD(str,e) //月发生变化时日期联动  
  {  
    // e 是第几个main表单 如果没有传参默认第一个
    if(e == undefined){
      e = 0
    }
  var YYYYvalue = document.getElementsByTagName('main')[e].children.YYYY.options[document.getElementsByTagName('main')[e].children.YYYY.selectedIndex].value;  
  if (str == ""){DD.outerHTML = strDD; return;}  
  var n = MonHead[str - 1];  
  if (str ==2 && IsPinYear(YYYYvalue)) n++;  
  writeDay(n,e)  
  }  
  function writeDay(n,j) //据条件写日期的下拉框  
  {  
  var s = strDD.substring(0, strDD.length - 9);  
  for (var i=1; i<(n+1); i++)  
  s += "<option value='" + i + "'> " + i + "</option>\r\n";  
  document.getElementsByTagName('main')[j].children.DD.outerHTML = s +"</select>";  
  }  
  function IsPinYear(year)//判断是否闰平年  
  { return(0 == year%4 && (year%100 !=0 || year%400 == 0))}  
  //-->